<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/3
 * Time: 16:05
 */
namespace Api\Controller;
require 'printhelper.php';

use Think\Controller;

class PrintOrderController extends Controller
{

    public function printHtml()
    {
        $uuid = "";
        /*$uuid="3358652f9b4ae98a";*/
        //查询uuid
        $config = M("printConfig")->field()->where(array(
            "id" => 1
        ))->find();
        if($config){
            $uuid = $config['uuid'];
        }

        $order_id = I('get.order_id');
        //实例化
        $helper = new \Printhelper();
        $printUrl = "http://mytest.bndvip.com/index.php/api/printOrder/buildHtml?order_id=".$order_id;
        echo $helper->printHtmlContent($uuid, $printUrl, 160944);
    }

    public function buildHtml(){
        //打印订单
        $order_id = I('get.order_id');
        $order_id = "H413110343566217";
        //查询订单的信息
        $result = M('order')->alias("o")->join("join meal_order_detail as v on o.id=v.order_id")
            ->join('meal_dishes c ON c.id = v.dish_id')
            ->field('o.id,o.create_time,c.name,v.price,v.count,v.amount,o.pay_amount,o.desk_number,o.people_number,v.attribute')
            ->where("order_id='$order_id'")
            ->select();
        //查出属性值
        if($result){
            $this->assign('desk_number',$result[0]['desk_number']);
            $this->assign('people_number',$result[0]['people_number']);
            $this->assign('pay_amount',$result[0]['pay_amount']);
            $this->assign('create_time',$result[0]['create_time']);
            $this->assign('id',$result[0]['id']);
        }else{
            $this->assign('desk_number',"");
            $this->assign('people_number',"");
            $this->assign('pay_amount',"");
            $this->assign('create_time',"");
            $this->assign('id',"");
        }

        $this->assign('result', $result);
        $this->display();

    }
}